package net.tngou.tpage.service;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import net.tngou.tpage.jdbc.OrderType;
import net.tngou.tpage.pojo.Basedata;

/**
 * 
 * @author tngou@tngou.net
 *
 */
public class BasedataService extends BaseService {

	
	
	/**
	 * 取得数据
	 * @param id
	 * @return
	 */
	public JSONArray combotree(long id) {
		JSONArray array= new JSONArray();
		List<?> list = getList("parentId="+id, "seq", OrderType.ASC, Basedata.class);
		if(list==null||list.isEmpty())
		{
			return array;
		}	
		list.forEach(e->{
			 JSONObject jsonObject=  (JSONObject) JSONObject.toJSON(e);
			  JSONArray ay = combotree(id);
			  if(ay.size()>0)jsonObject.put("children", ay);
			  array.add(jsonObject);
		});
		return array;
		
	}
}
